//
//  COCreateCollectionViewCell.swift
//  CocoProject
//
//  Created by Ruthless on 2023/8/28.
//

import UIKit
import QMUIKit

class COCreateCollectionViewCell: UICollectionViewCell {
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        configUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func configUI() {
        
        backgroundColor = .rgba(17, 7, 41, 1)
        contentView.addSubview(button)
        
        button.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
    }
    
    func addLayer(_ isOk: Bool) {
        if isOk {
            button.layer.insertSublayer(gadrenLayer, at: 0)
            button.layer.borderWidth = 0
        } else {
            gadrenLayer.removeFromSuperlayer()
            button.layer.borderWidth = 1
        }
    }
    
    private lazy var gadrenLayer: CAGradientLayer = {
        let bgLayer1 = CAGradientLayer()
        bgLayer1.colors = [UIColor.rgba(218, 67, 255).cgColor, UIColor.rgba(82, 28, 255).cgColor]
        bgLayer1.locations = [0, 1]
        bgLayer1.frame = CGRect(x: 0, y: 0, width: (SCREENWIDTH-36-40)/4, height: 33)
        bgLayer1.startPoint = CGPoint(x: 1, y: 0.56)
        bgLayer1.endPoint = CGPoint(x: 0.56, y: 0.56)
        return bgLayer1
    }()
    
    private(set) lazy var button: UIButton = {
        let btn = UIButton()
        btn.isUserInteractionEnabled = false
        btn.setTitleColor(.white, for: .normal)
        btn.titleLabel?.font = .medium(12)
        btn.layer.masksToBounds = true
        btn.layer.cornerRadius = 16
        btn.layer.borderColor = UIColor.white.cgColor
        return btn
    }()
}
